package com.thread.exem;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author げっしょく
 * @date 2021/8/7
 */
public class Fooler extends Thread{

    public Fooler(ArrayBlockingQueue<String> array) {
        this.array = array;
    }

    @Override
    public void run() {
        while (true) {
            String take = null;
            try {
                take = array.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("小朋友正在吃" + take);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
    private ArrayBlockingQueue<String> array;

}

class Cooker extends Thread{
    private ArrayBlockingQueue<String> array;

    public Cooker(ArrayBlockingQueue<String> array) {
        this.array = array;
    }

    @Override
    public void run() {
        while (true){
            try {
                array.put("垃圾食品");
                System.out.println("厨师正在做垃圾食品");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
